import constant from './constant'
export default {
	methods: {
		//orderstatus 2:开始-已派工,3:开始-已接单,4:开始-接单超时,5:开始-已退单
		//6:现场处理,7: 等待,8:完工,9:取消,10:返工,11:结束			
		showBtn(woItem) {
			let limit = this.ButtonLimit();
			let IsShowAcceptorderBtn = false; //接单按钮
			let IsShowReservationBtn = false; //预约按钮
			let IsShowVisitBtn = false; //上门按钮
			let IsShowCompleteBtn = false; //完工按钮
			let IsShowReCompleteBtn = false; //重新完工按钮
			let IsShowEvaluateBtn = false; //评价按钮
			let showMore = false;
			let orderstatus = woItem.OrderStatus
			if ((orderstatus == constant.WORDER_START_dispatchedworker ||
					orderstatus == constant.WORDER_START_ordertimeout) && limit.isAcceptBtnAuth) {
				IsShowAcceptorderBtn = true;
				showMore = false;
			} else if ((orderstatus == constant.WORDER_START_receivedorders ||
				orderstatus == constant.WORDER_rework)&&!woItem.IsAppSubmitFinished) {
				if (limit.isAppointmentBtnAuth)
					IsShowReservationBtn = true;
				if (limit.isFieldServiceBtnAuth)
					IsShowVisitBtn = true;
				showMore = true;
			} else if (orderstatus == constant.WORDER_worksitehandle &&
				!woItem.IsAppSubmitFinished) {
				if (limit.isReportFinishedBtnAuth)
					IsShowCompleteBtn = true;
				showMore = false;
			} else if (orderstatus == constant.WORDER_worksitehandle &&
				woItem.AllowAppReSubmit && woItem.IsAppSubmitFinished) {
				IsShowReCompleteBtn = true;
				showMore = false;
			} else if (orderstatus == constant.WORDER_finished) {
				IsShowEvaluateBtn = true;
				showMore = false;
			}
			let retult = {
				"IsShowAcceptorderBtn": IsShowAcceptorderBtn,
				"IsShowReservationBtn": IsShowReservationBtn,
				"IsShowVisitBtn": IsShowVisitBtn,
				"IsShowCompleteBtn": IsShowCompleteBtn,
				"IsShowReCompleteBtn": IsShowReCompleteBtn,
				"IsShowEvaluateBtn": IsShowEvaluateBtn,
				"showMore": showMore,
			};
			return retult;
		},
		IsDisplayTab() {
			//tab
			let isAcceptingTapAuth = false; // 待接单tab页权限
			let isProcessingTapAuth = false; // 待处理tab页权限
			let isSubmittedTapAuth = false; // 提交完工tab页权限
			let isDoneTapAuth = false; // 已完成tab页权限
			let authList = this.UserInfo.Jurisdiction;

			for (let authIndex in authList) {
				let authItem = authList[authIndex];
				if (authItem.toLowerCase() == 'wolistaccepting') {
					isAcceptingTapAuth = true;
				} else if (authItem.toLowerCase() == 'wolistprocessing') {
					isProcessingTapAuth = true;
				} else if (authItem.toLowerCase() == 'wolistsubmitted') {
					isSubmittedTapAuth = true;
				} else if (authItem.toLowerCase() == 'wolistdone') {
					isDoneTapAuth = true;
				}
			}
			return {
				"isAcceptingTapAuth": isAcceptingTapAuth,
				"isProcessingTapAuth": isProcessingTapAuth,
				"isSubmittedTapAuth": isSubmittedTapAuth,
				"isDoneTapAuth": isSubmittedTapAuth,
			}
		},
		ButtonLimit() {
			let hasWoListPageAuth = false; /* 验证用户是否存在工单使用权限 */
			let isAcceptBtnAuth = false; // 接单按钮权限
			let isAppointmentBtnAuth = false; // 接单预约权限
			let isFieldServiceBtnAuth = false; // 接单上门权限
			let isReportFinishedBtnAuth = false; // 接单完工权限
			//tab 
			let isAcceptingTapAuth = false; // 待接单tab页权限
			let isProcessingTapAuth = false; // 待处理tab页权限
			let isSubmittedTapAuth = false; // 提交完工tab页权限
			let isDoneTapAuth = false; // 已完成tab页权限
			//工单详情页按钮
			let isProcessReminderBtnAuth = false; //催单处理
			let isConsultingDoneBtnAuth = false; //咨询完工
			let isReworkBtnAuth = false; //返工
			let isUpdateOrderBtnAuth = false; // 更新工单按钮
			let isIOTChangePlateBtnAuth = false; // 物联网换板按钮
			let authList = this.UserInfo.Jurisdiction;
			// 遍历用户主页功能块权限
			for (let authIndex in authList) {
				let authItem = authList[authIndex];
				if (authItem.toLowerCase() == 'woentry') {
					hasWoListPageAuth = true;
				} else if (authItem.toLowerCase() == 'woacceptcommand') {
					isAcceptBtnAuth = true;
				} else if (authItem.toLowerCase() == 'woappointmentcommand') {
					isAppointmentBtnAuth = true;
				} else if (authItem.toLowerCase() == 'wofieldservicecommand') {
					isFieldServiceBtnAuth = true;
				} else if (authItem.toLowerCase() == 'woreportfinishedcommand') {
					isReportFinishedBtnAuth = true;
				} else if (authItem.toLowerCase() == 'wolistaccepting') {
					isAcceptingTapAuth = true;
				} else if (authItem.toLowerCase() == 'wolistprocessing') {
					isProcessingTapAuth = true;
				} else if (authItem.toLowerCase() == 'wolistsubmitted') {
					isSubmittedTapAuth = true;
				} else if (authItem.toLowerCase() == 'wolistdone') {
					isDoneTapAuth = true;
				} else if (authItem.toLowerCase() == 'woproccessremind') {
					//催单处理
					isProcessReminderBtnAuth = true;
				} else if (authItem.toLowerCase() == 'woconsultfinish') {
					//咨询完工
					isConsultingDoneBtnAuth = true
				} else if (authItem.toLowerCase() == 'iotreplacemasterboard-serviceorderentry') {
					//物联网换板按钮
					isIOTChangePlateBtnAuth = true;
				} else if (authItem.toLowerCase() == 'woreworkcommand') {
					//返工
					isReworkBtnAuth = true;
				} else if (authItem.toLowerCase() == 'woinfoupdatecommand') {
					//更新工单
					isUpdateOrderBtnAuth = true;
				}
			}
			return {
				hasWoListPageAuth: hasWoListPageAuth,
				isAcceptBtnAuth: isAcceptBtnAuth,
				isAppointmentBtnAuth: isAppointmentBtnAuth,
				isFieldServiceBtnAuth: isFieldServiceBtnAuth,
				isReportFinishedBtnAuth: isReportFinishedBtnAuth,
				isAcceptingTapAuth: isAcceptingTapAuth,
				isProcessingTapAuth: isProcessingTapAuth,
				isSubmittedTapAuth: isSubmittedTapAuth,
				isDoneTapAuth: isDoneTapAuth,
				isProcessReminderBtnAuth: isProcessReminderBtnAuth, //催单处理
				isConsultingDoneBtnAuth: isConsultingDoneBtnAuth, //咨询完工
				isReworkBtnAuth: isReworkBtnAuth, //返工
				isUpdateOrderBtnAuth: isUpdateOrderBtnAuth, // 更新工单按钮
				isIOTChangePlateBtnAuth: isIOTChangePlateBtnAuth, // 物联网换板按钮
			};
		},
		//工单详情按钮
		WoDetailsShowBtn(WoItem) {
			//debugger;
			let limit = this.ButtonLimit();
			let IsShowAcceptorderBtn = false; //接单
			let IsShowReservationBtn = false; //预约
			let IsShowVisitBtn = false; //上门
			let IsShowCompleteBtn = false; //完工按钮
			let isShowProcessReminderBtn = false; //催单处理
			let isShowConsultingDoneBtn = false; //咨询完工
			let isShowReworkBtn = false; //返工
			let isShowUpdateOrderBtn = false; // 更新工单按钮
			let isShowIOTChangePlateBtn = false; // 物联网换板按钮
			let isShowCreateAssemblyBomBtn = true; //生成配件行
			let orderstatus = WoItem.OrderStatus
			if ((orderstatus == constant.WORDER_START_dispatchedworker ||
					orderstatus == constant.WORDER_START_ordertimeout) && limit.isAcceptBtnAuth) {
				//接单
				IsShowAcceptorderBtn = true;
			}
			if (orderstatus == constant.WORDER_START_receivedorders ||
				orderstatus == constant.WORDER_rework || orderstatus == constant.WORDER_worksitehandle) {
				//预约
				if (limit.isAppointmentBtnAuth && WoItem.IsAppSubmitFinished == true && WoItem.AllowAppReSubmit == false)
					IsShowReservationBtn = false;
				else {
					IsShowReservationBtn = true;
				}
				//上门
				if (limit.isFieldServiceBtnAuth && WoItem.IsAppSubmitFinished == true && WoItem.AllowAppReSubmit == false)
					IsShowVisitBtn = false;
				else
					IsShowVisitBtn = true;
			}
			if ((orderstatus == constant.WORDER_worksitehandle || orderstatus == constant.WORDER_rework) &&
				limit.isReportFinishedBtnAuth) {
				//完工
				if (WoItem.IsAppSubmitFinished == true && WoItem.AllowAppReSubmit == false) {
					IsShowCompleteBtn = false;
				} else {
					IsShowCompleteBtn = true;
				}
			}
			if ((orderstatus == constant.WORDER_START_dispatchedworker || orderstatus == constant.WORDER_START_receivedorders ||
					orderstatus == constant.WORDER_START_ordertimeout || orderstatus == constant.WORDER_worksitehandle ||
					orderstatus == constant.WORDER_waitfor || orderstatus == constant.WORDER_rework) && limit.isProcessReminderBtnAuth) {
				//催单处理
				var leftReminderTimes = WoItem.LeftReminderTimes;
				if (leftReminderTimes > 0) {
					isShowProcessReminderBtn = true;
				}
			}
			if (limit.isConsultingDoneBtnAuth && (orderstatus == constant.WORDER_worksitehandle || orderstatus ==
					constant.WORDER_rework)) {
				//咨询完工
				if (WoItem.IsAppSubmitFinished == true && WoItem.AllowAppReSubmit == false) {
					isShowConsultingDoneBtn = false;
				} else {
					isShowConsultingDoneBtn = true;
				}
			}
			if (limit.isReworkBtnAuth && orderstatus == constant.WORDER_finished) {
				//返工
				isShowReworkBtn = true;
			}
			if (limit.isUpdateOrderBtnAuth && (orderstatus == constant.WORDER_START_receivedorders ||
					orderstatus == constant.WORDER_worksitehandle || orderstatus == constant.WORDER_waitfor ||
					orderstatus == constant.WORDER_rework)) {
				//更新工单
				isShowUpdateOrderBtn = true;
			}
			if (limit.isIOTChangePlateBtnAuth && WoItem.WoFinishType == 2 &&
				(orderstatus == constant.WORDER_START_returnedorder || orderstatus == constant.WORDER_worksitehandle ||
					orderstatus == constant.WORDER_waitfor || orderstatus == constant.WORDER_finished ||
					orderstatus == constant.WORDER_cancel || orderstatus == constant.WORDER_rework)) {
				// 物联网换板按钮
				isShowIOTChangePlateBtn = true;
			}
			return {
				"IsShowAcceptorderBtn": IsShowAcceptorderBtn,
				"IsShowReservationBtn": IsShowReservationBtn,
				"IsShowVisitBtn": IsShowVisitBtn,
				"IsShowCompleteBtn": IsShowCompleteBtn,
				"isShowProcessReminderBtn": isShowProcessReminderBtn,
				"isShowConsultingDoneBtn": isShowConsultingDoneBtn,
				"isShowReworkBtn": isShowReworkBtn,
				"isShowUpdateOrderBtn": isShowUpdateOrderBtn,
				"isShowIOTChangePlateBtn": isShowIOTChangePlateBtn,
				"isShowCreateAssemblyBomBtn": isShowCreateAssemblyBomBtn,
			}
		},
		//完工跳转页面
		GoToPage(FinishType, WoId) {
			if (FinishType == constant.WORDER_FINISH_Intall) {
				uni.navigateTo({
					url: "../wocomplete/install/install?orderDetailId=" + WoId,
				})
			} else if (FinishType == constant.WORDER_FINISH_Maintain) {
				uni.navigateTo({
					url: "../wocomplete/guarantee/guarantee?orderDetailId=" + WoId,
				})
			} else if (FinishType == constant.WORDER_FINISH_Repair) {
				uni.navigateTo({
					url: "../wocomplete/repair/repair?orderDetailId=" + WoId,
				})
			} else if (FinishType == constant.WORDER_FINISH_TradeIn) {
				// uni.navigateTo({
				// 	url: "../wocomplete/guarantee/guarantee?orderDetailId="+WoId,
				// })
			} else if (FinishType == constant.WORDER_FINISH_Relocation) {
				uni.navigateTo({
					url: "../wocomplete/move/move?orderDetailId=" + WoId,
				})
			} else if (FinishType == constant.WORDER_FINISH_ReturnOrReplace) {
				uni.navigateTo({
					url: "../wocomplete/replace/replace?orderDetailId=" + WoId,
				})
			}
		},
	}
}
